import {
	RetCodeMsg,
	CodeMsg
} from '@/utils/errorCode.js'
import {enRetCodeMsg,
	enCodeMsg} from '@/lang/en-code'
import {
	pointCode
} from '@/utils/point/pointCode.js'
import {
	requestPointData
} from '@/utils/point/postPointData.js'
const {
	ECB
} = require('@/utils/aes.js');

const {
	Signature
} = require('@/utils/_util.js');

const {
	decodeURI
} = require('@/utils/util.js');
const {
	BaseURL,
	BaseURLRDSVIOT,
	BaseURLRS,
	BaseURLWeather,
	BaseURLRSJFTECHWS,
	BaseURLRDSXM,
	BaseURLCAPSXM,
	BaseURLSW,
	BaseURLPoint,
	BaseURLPointQuery,
	BaseURLRDSJFTECHWS,
	BaseURLGWP,
	BaseURLRDS
} = require('./baseUrl.js')
const {logs} = require('@/utils/logs.js');
const signature = new Signature();
const CONTENT_TYPE_JSON = 'application/json; charset=UTF-8';
const CONTENT_TYPE_FORM = 'application/x-www-form-urlencoded';
const CONTENT_TYPE_stream = 'application/octet-stream';

// 引入v3版本方法
import {encryptAES,decrypt,getSignature,generateUniqueCode,requestV3} from "./request_v3";

export class Api {
	constructor(uuid, appKey, appSecret, movedCard) {
		this.uuid = uuid;
		this.appKey = appKey;
		this.appSecret = appSecret;
		this.movedCard = movedCard;
		this.tms = signature.tms;
		this.sig = signature.get(this.uuid, this.appKey, this.appSecret, this.movedCard);
	}
	/**
	 * JSON提交
	 * @param {Object} options wx.request请求接口的参数
	 * @param {Function} callback 请求成功后的回调函数
	 * @param {Boolean} decode 返回结果是否需要 解码，true需要，false不需要
	 * @param {Boolean} simple 返回结果是否需要 简化，true简化，false不简化
	 */

	postJson(options, callback, decode = false, simple = true, pointData) {
		const header = this.getRequestHeader(options.header);
		uni.request({
			method: 'POST',
			url: options.url,
			data: options.data,
			timeout: 60000,
			header,
			success: (res) => {
				// console.log('云存储=====', options.url,'==========',res,res.data);
				// 需要获取完整的返回数据
				if (!simple) {
					this.uploadLogs(options, res)
					callback(res);
					return;
				}
				// console.log('api:postJson:', res);
				// 兼容云存储(caps.secu100.net)的请求
				// 编译或不编译的数据
				this.handleResponse(options, res, decode, callback, pointData);
			},
			fail: (err) => {
				logs({
					apiUrl: options.url,
					data: err,
					fail: '请求失败'
				}, 'error')
				this.handleFailure(options, err);
			},
			complete: (info) => {
				// console.log('complete:',info);
			}
		});
	}
	postJsonMultifield(options, callback, decode = false, simple = true, responseType = 'text', callbackError,
		pointData) {
		const header = this.getRequestHeader(options.header);
		uni.request({
			method: 'POST',
			url: options.url,
			data: options.data,
			timeout: 60000,
			header,
			responseType,
			success: (res) => {
				if (!simple) {
					this.uploadLogs(options, res)
					callback(res);
					return;
				}
				this.handleResponse(options, res, decode, callback, pointData);
			},
			fail: (err) => {
				logs({
					apiUrl: options.url,
					data: err,
					fail: '请求失败'
				}, 'error')
				this.handleFailure(options, err, callbackError);
			},
			complete: (info) => {}
		});
	}
	// 请求header
	getRequestHeader(customHeader) {
		let lang = uni.getSystemInfoSync().language;
		return {
			uuid: this.uuid,
			appKey: this.appKey,
			// Authorization: uni.getStorageSync('accessToken'),
			'Content-type': CONTENT_TYPE_JSON,
			'Accept-Language': lang == 'zh-CN'?'zh_CN':'en',
			...customHeader
		};
	}
	//请求结果
	handleResponse(options, res, decode, callback, pointData) {
		// console.log(pointCode, 'pointCode')
		// pointData = 400109
		const data = res.data || {};
		if (!data.code) {
			if (data.ret === 200) {
				callback(data);
				this.uploadLogs(options, data);
			} else {
				uni.showToast({
					title: res.data.msg,
					icon: 'none'
				});
				// this.handleRequestError(options, data, pointData);
				logs({
					apiUrl: options.url,
					data: data
				}, 'error')
			}
		} else {
			const result = decode ? decodeURI(data || '{}') : data || {};
			// this.handlePointCode(options, result, pointData)
			if (result.code === 2000) {
				if (data.data && data.data.Ret && data.data.Ret != 100) {
					let lang = uni.getSystemInfoSync().language
					console.log(lang, 'lang1')
					uni.showToast({
						title: (lang == 'zh-CN'? RetCodeMsg[result.code] :enRetCodeMsg[result.code]) || data.data.retMsg,
						icon: 'none',
						duration: 2000
					});
					logs({
						apiUrl: options.url,
						data: result
					}, 'error')
					// this.handleRequestError(options, result, pointData);
				} else {
					callback(data.data);
					this.uploadLogs(options, data);
				}
			} else if (result.code === 200) {
				callback(result.data);
				this.uploadLogs(options, result);
			} else {
				logs({
					apiUrl: options.url,
					header: options.header,
					requestData: options.data,
					data: result
				}, 'error')
				this.handlePointCode(options, result, pointData)
				this.handleRequestError(options, result, pointData);
			}
		}
	}
	// 处理埋点code
	handlePointCode(options, result, code) {
		const pointCodeObj = pointCode[code];
		if (!pointCodeObj) return
		let obj = {
			code: code.toString(),
			eventName: pointCodeObj.eventName,
			t: Math.floor(Date.now() / 1000).toString()
		};
		if ('devId' in pointCodeObj) {
			obj.devId = options.data.sn || null
		}
		if ('roomId' in pointCodeObj) {
			obj.roomId = options.data.roomId || null
		}
		if ('reason' in pointCodeObj) {
			obj.reason = result.msg
		}
		if ('action' in pointCodeObj) {
			obj.action = pointCode.action
		}
		if ('error_code' in pointCodeObj) {
			obj.error_code = result.code
		}
		if ('request_code' in pointCodeObj) {
			obj.request_code = pointCode.request_code
		}
		console.log(obj, '处理code')
		requestPointData(obj)
	}
	//请求错误处理
	handleRequestError(options, result, pointData) {
		if (result.code == -91003 ||
			result.code == 5010 ||
			result.code == 5011 ||
			result.msg.includes('token')) {
			const accessToken = uni.getStorageSync('accessToken') || '';
			if (accessToken) {
				uni.showToast({
					title: '登录已过期，请重新登录',
					icon: 'none',
				});
				uni.setStorageSync('isTokenExpire', true)
			}
			uni.removeStorageSync('accessToken');
			uni.removeStorageSync('userInfo');
			uni.removeStorageSync('checkAutoLogin');
			const isToken = uni.getStorageSync('isToken');
			if (!isToken) {
				if (getApp().globalData.mqtt.client) {
					getApp().globalData.mqtt.close()
				}
				setTimeout(() => {
					let page = getCurrentPages()
					if (page.length === 1) {
						uni.redirectTo({
							url: '/jvss/pages/login/login'
						})
					} else {
						uni.reLaunch({
							url: '/jvss/pages/login/login'
						})
					}
				}, 1000)
			} else {
				if (!uni.getStorageSync('userInfo')) {
					uni.showToast({
						title: '登录已过期，请重新登录',
						icon: 'none'
					});
					uni.reLaunch({
						url: '/jvss/pages/login/login'
					})
				}
				return
			}
		}
		if (result.code != 4100 && result.code != 4118 && result.code !=4123) {
			let lang = uni.getSystemInfoSync().language
			console.log(lang, 'lang2')
			if(result.code == -91018) {
				uni.showToast({
					title: (lang == 'zh-CN'? CodeMsg[91018] :enCodeMsg[91018]),
					icon: 'none'
				})
				return;
			}
			const toastMessage = (lang == 'zh-CN'? CodeMsg[result.code] :enCodeMsg[result.code]) || (result.msg.includes(
				'access token ??') ? '登录已过期，请重新登录' : result.msg);
			uni.showToast({
				title: toastMessage,
				icon: 'none'
			});
		}else{
			uni.hideLoading()
		}
	}
	// 接口连接失败处理
	handleFailure(options, err, callbackError) {
		console.log('api:fail:', err);
		// #ifdef MP-WEIXIN
		logs({
			apiUrl: options.url,
			data: err,
			fail: '请求失败'
		}, 'error');
		// #endif
		if (typeof callbackError === 'function') {
			callbackError(err);
		}
	}

	/**
	 * body提交
	 * @param {Object} options wx.request请求接口的参数
	 * @param {Function} callback 请求成功后的回调函数
	 * @param {Boolean} decode 返回结果是否需要 解码，true需要，false不需要
	 * @param {Boolean} isAuthor 是否可重复登录, true可以，false不可以
	 * @param {Boolean} simple 返回结果是否需要 简化，true简化，false不简化
	 */
	postForm(options, callback, decode = true, isAuthor = true, simple = true,all = false,pointData) {
		let header = {
			uuid: this.uuid,
			appKey: this.appKey,
			Authorization: !isAuthor ? uni.getStorageSync('accessToken') : '',
			'Content-type': CONTENT_TYPE_FORM,
			'Accept-Language': 'zh'
		};
		header = Object.assign(header, options.header);
		uni.request({
			method: 'POST',
			url: options.url,
			data: options.data,
			header: header,
			success: (res) => {
				// 需要获取完整的返回数据
				if (!simple) {
					callback(res);
					this.uploadLogs(options, res)
					return;
				}
				const result = decode ? decodeURI(res.data || '{}') : res.data || {};
				console.log('api:postForm-------:', result );
				this.uploadLogs(options, result)
				if(all){
					callback(result)
					return
				}
				if (result.code === 2000) {
					callback(result.data);
				} else {
					if (result.code == 4000 && result.data == 'Incorrect+username+or+password') {
						result.code = 'incorrectName'
					}
					let lang = uni.getSystemInfoSync().language
					console.log(lang, 'lang1')
					uni.showToast({
						title: (lang == 'zh-CN'? CodeMsg[result.code] :enCodeMsg[result.code]) || result.msg,
						icon: 'none'
					});
					logs({
						apiUrl: options.url,
						data: options.data
					}, 'error')
				}
			},
			fail: (err) => {
				// #ifdef MP-WEIXIN
				logs({
					apiUrl: options.url,
					data: err,
					fail: '请求失败'
				}, 'error')
				// #endif
			},
			complete: (info) => {}
		});
	}
	// 获取日历报警消息
	getMsgCalendar(data, token, callback) {
		this.postJson({
				url: `${BaseURLRDSJFTECHWS}/v2/rtc/device/queryCalendar/${token}`,
				data: data
			},
			(result) => {
				callback(result)
			}
		)
	}

	//上传离线日志
	uploadLogs(opt, result) {
		// #ifdef MP-WEIXIN
		logs({
			apiUrl: opt.url,
			requestData: opt.data,
			result: result
		}, 'info', false)
		// #endif
	}

	/**------------------- 系统消息通知----------------------------*/
	getNotifyList(data, callback) {
		this.postJson({
				url: `${BaseURL}/notifyLog/list`,
				data: data
			},
			(result) => {
				callback(result);
			}
		);
	}
	/** ===========================设备的用户管理========================================================================== */
	// 分页查询开锁指纹/卡/密码
	getUnlockInfoListByPage(data, callback) {
		this.postJson({
				url: `${BaseURL}/unlockInfo/getListByPage`,
				data: data
			},
			(result) => {
				callback(result);
			}
		);
	}

	/** ===========================消息推送======================================================================================= */

	//上传埋点
	pointUpload(data, callback) {
		this.postJson({
				url: `${BaseURLPoint}/point/upload`,
				data: data
			},
			(result) => {
				callback(result);
			}
		);
	}

	//埋点数据查询
	pointQuery(data, callback) {
		this.postJson({
				url: `${BaseURLPointQuery}/point/query`,
				data: data
			},
			(result) => {
				callback(result);
			}
		);
	}

	//埋点分类事件数据查询
	pointQueryClass(data, callback) {
		this.postJson({
				url: `${BaseURLPointQuery}/point/queryClass`,
				data: data
			},
			(result) => {
				callback(result);
			}
		);
	}

	/** ===========================消息推送======================================================================================= */
	//订阅所有设备
	subscribeAllDeviceBatchSubscribe(data, callback) {
		this.postJson({
				url: `${BaseURL}/wx/device/message/batchSubscribe`,
				data: data
			},
			(result) => {
				callback(result);
			},
			false
		);
	}
	//获取设备订阅状态
	getDeviceSubscribeStatus(data, callback) {
		this.postJson({
				url: `${BaseURL}/wx/device/message/querySubscribe`,
				data: data
			},
			(result) => {
				callback(result);
			},
			false
		);
	}
	// 获取票据、模板、openID
	getDeviceTicket(data, callback) {
		this.postJson({
				url: `${BaseURL}/wx/device/message/getDeviceSnTicket`,
				data: data
			},
			(result) => {
				callback(result);
			},
			false
		);
	}
	//获取是否授权
	getDeviceAuth(data, callback) {
		this.postJson({
				url: `${BaseURL}/wx/device/message/getDeviceAuth`,
				data: data
			},
			(result) => {
				callback(result);
			},
			false
		);
	}
	// 消息订阅
	subscribePMSMessage(data, callback, decode = false, simple = true) {
		this.postJson({
				url: `${BaseURL}/wx/device/message/subscribe`,
				data: data
			},
			(result) => {
				callback(result);
			},decode,simple
		);
	}
	// 取消订阅
	cancelSubscribeMessage(data, callback) {
		this.postJson({
				url: `${BaseURL}/wx/device/message/unSubscribe`,
				data: data
			},
			(result) => {
				callback(result);
			},
			false
		);
	}
	// pms回调
	pmsCallback(data, callback) {
		this.postJson({
				url: `${BaseURL}/wx/device/message/pmsCallback`,
				data: data
			},
			(result) => {
				callback(result);
			},
			false
		);
	}
	// 小程序消息回调
	wxMsgCallback(data, callback) {
		this.postJson({
				url: `${BaseURL}/wx/device/message/wxMsgCallback`,
				data: data
			},
			(result) => {
				callback(result);
			},
			false
		);
	}
	// 开放平台 RS带授权码接口 `${BaseURLRS}/login/va1/${this.tms}/${this.sig}.rs`,
	getCurrentAccountDevcieList(data,callback) {
		return this.postForm({
				url: `${BaseURLRSJFTECHWS}/mdlistCode/v1/${this.tms}/${this.sig}.rs`,
				data: data
			},
			(result) => {
				callback(result);
			},true,false
		);
	}
	/** ============================登录============================================================================================= */
	//手机号注册
	mobileRegister(data, callback) {
		return this.postForm(
		{
		    url: `${BaseURLRS}/userregPhone/v1/${this.tms}/${this.sig}.rs`,
			data: data,
		},
		(result) => {
		    callback(result);
		},
		true,
		true,true,false,400001
		);
	}
	// 账号登录 `${BaseURLRS}/login/va1/${this.tms}/${this.sig}.rs`,
	getUserInfo(account, pass, callback) {
		return this.postForm({
				url: `${BaseURLRS}/loginExist/va1/${this.tms}/${this.sig}.rs`,
				data: {
					account: ECB.encrypt(account, this.tms, this.appSecret),
					pass: ECB.encrypt(pass, this.tms, this.appSecret)
				}
			},
			(result) => {
				callback(result);
			},true,true,true,false,400101
		);
	}
	//获取名称
	getUserinfo2(callback) {
		return this.postForm({
				url: `${BaseURLRS}/userinfo2/v1/${this.tms}/${this.sig}.rs`,
			},
			(result) => {
				callback(result);
			},
			true,
			false,
			false
		);
	}
	// 微信登录
	getAccessToken(code, callback) {
		return this.postForm({
				url: `${BaseURLRS}/wx/login/va1/${this.tms}/${this.sig}.rs`,
				data: {
					code: ECB.encrypt(code, this.tms, this.appSecret)
				}
			},
			(result) => {
				callback(result);
			},true,true,true,false,400109
		);
	}
	// 获取用户名和密码（暂未使用）
	getUsernameAndPass(code, callback) {
		// 加密unionId
		const unionId = ECB.encrypt(code, this.tms, this.appSecret);
		const data = {
			type: 1,
			unionId
		};
		return this.postForm({
				url: `${BaseURLRS}/wx/unionId2U/v1/${this.tms}/${this.sig}.rs`,
				data: data,
				header: {
					uname: uni.getStorageSync('user').uname,
					upass: uni.getStorageSync('user').upass
				}
			},
			(result) => {
				callback(result);
			}
		);
	}
	// 绑定微信
	bindWxUser(username, password, uname, upass, callback) {
		const data = {
			name: username,
			password: password,
			confirmPass: password,
			uname,
			upass,
			hasUser: false
		};
		return this.postForm({
				url: `${BaseURLRS}/wx/bind/v1/${this.tms}/${this.sig}.rs`,
				data: data
			},
			(result) => {
				callback(result);
			}
		);
	}
	//忘记密码功能--发送手机验证码
	sendMobileVerifyCode(data, callback,all=false) {
		// const data = {
		// 	type: 'fp',
		// 	phone: phone,
		// 	codeSize: 6
		// };
		return this.postForm({
				url: `${BaseURLRS}/scphone/v1/${this.tms}/${this.sig}.rs`,
				data: data,
			},
			(result) => {
				callback(result);
			},true,true,true,all,400201
		);
	}
	//忘记密码功能--发送邮箱验证码
	sendEmailVerifyCode(mail, callback) {
		const data = {
			type: 'fp',
			mail: mail,
			language: 'zh'
		};
		return this.postForm({
				url: `${BaseURLRS}/scmail/v1/${this.tms}/${this.sig}.rs`,
				data: data,
			},
			(result) => {
				callback(result);
			},true,true,true,false,400202
		);
	}
	//忘记密码功能--发送邮箱链接
	sendfpLink(mail, callback) {
		const data = {
			mail: mail,
			lang: 'zh_CN'
		};
		return this.postForm({
				url: `${BaseURLRS}/fpLink/v1/${this.tms}/${this.sig}.rs`,
				data: data,
			},
			(result) => {
				callback(result);
			},true,true,true,false,400013
		);
	}
	//忘记密码功能--邮箱验证
	sendfpLinkHasAct(userId, callback) {
		const data = {
			userId: userId,
		};
		return this.postForm({
				url: `${BaseURLRS}/fpLinkHasAct/v1/${this.tms}/${this.sig}.rs`,
				data: data,
			},
			(result) => {
				callback(result);
			},
			true,
			true,
			false
		);
	}
	//忘记密码功能--验证码验证
	judgeVerifyCode(data, callback) {
		return this.postForm({
				url: `${BaseURLRS}/usercpc/v1/${this.tms}/${this.sig}.rs`,
				data: data,
			},
			(result) => {
				callback(result);
			},true,true,true,false,400204
		);
	}
	//忘记密码功能--手机重置密码
	phoneResetPassword(data, callback) {
		return this.postForm({
				url: `${BaseURLRS}/fpphone/v1/${this.tms}/${this.sig}.rs`,
				data: data,
			},
			(result) => {
				callback(result);
			},true,true,true,false,400206
		);
	}
	//忘记密码功能--邮箱重置密码
	mailResetPassword(data, callback) {
		return this.postForm({
				url: `${BaseURLRS}/fpmail/v1/${this.tms}/${this.sig}.rs`,
				data: data,
			},
			(result) => {
				callback(result);
			},true,true,true,false,400207
		);
	}
	//删除账号
	userecancel(data, callback,all=false) {
		return this.postForm({
				url: `${BaseURLRS}/userecancel/v1/${this.tms}/${this.sig}.rs`,
				data: data,
			},
			(result) => {
				callback(result);
			},true,true,true,all,400501
		);
	}
	//修改名称
	modifyAccountNickname(data, callback) {
		this.postForm({
				url: `${BaseURLRS}/modifyAccountNickname/va1/${this.tms}/${this.sig}.rs`,
				data: data
			},
			(result) => {
				callback(result);
			},
			true,
			false
		);
	}
	//头像列表
	getDefaultHeadPortrait(data, callback) {
		this.postForm({
				url: `${BaseURLRS}/getDefaultHeadPortrait/va1/${this.tms}/${this.sig}.rs`,
				data: data
			},
			(result) => {
				callback(result);
			},
			true,
			false
		);
	}
	//头像列表
	getSpecialHeadPortrait(data, callback) {
		this.postForm({
				url: `${BaseURLRS}/getSpecialHeadPortrait/v1/${this.tms}/${this.sig}.rs`,
				data: data
			},
			(result) => {
				callback(result);
			},
			true,
			false
		);
	}
	//修改头像
	setDefaultHeadPortrait(data, callback) {
		this.postForm({
				url: `${BaseURLRS}/setDefaultHeadPortrait/v1/${this.tms}/${this.sig}.rs`,
				data: data
			},
			(result) => {
				callback(result);
			},
			true,
			false
		);
	}
	//修改家庭头像
	updateUserPic(data, callback) {
		this.postJson({
				url: `${BaseURL}/user/updateUserPic`,
				data: data
			},
			(result) => {
				callback(result);
			}
		);
	}
	// 绑定微信
	/** ============================权限============================================================================================= */
	// 查询权限配置列表(暂未使用)
	privilegeConfig(callback) {
		this.postForm({
				url: `${BaseURL}/privilege/privilegeConfig`
			},
			(result) => {
				callback(result);
			},
			false
		);
	}

	/** ============================用户组============================================================================================= */
	// 查询用户组列表
	getUserGroupListByPage(data, callback) {
		this.postJson({
				url: `${BaseURL}/userGroup/getUserGroupListByPage`,
				data: data
			},
			(result) => {
				callback(result);
			},false,true,407015
		);
	}
	// 新增用户组
	addUserGroup(data, callback, decode = false, simple = true) {
		this.postJson({
				url: `${BaseURL}/userGroup/addUserGroup`,
				data: data
			},
			(result) => {
				callback(result);
			},
			decode,simple,407006
		);
	}
	// 删除整个家庭组
	delUserGroup(data, callback) {
		this.postJson({
				url: `${BaseURL}/userGroup/delUserGroup`,
				data: data
			},
			(result) => {
				callback(result);
			},false,true,407003
		);
	}
	// 删除家庭组
	delCurrentUserGroup(data, callback) {
		this.postJson({
				url: `${BaseURL}/user/delCurrentUser`,
				data: data
			},
			(result) => {
				callback(result);
			},false,true,407004
		);
	}
	// 编辑用户组
	updateUserGroup(data, callback) {
		this.postJson({
				url: `${BaseURL}/userGroup/updateUserGroup`,
				data: data
			},
			(result) => {
				callback(result);
			},false,true,407007
		);
	}
	// 获取全部地区列表（暂时未使用）
	getAllRegion(data, callback) {
		this.postJson({
				url: `${BaseURL}/userGroup/getAllRegion`,
				data: data
			},
			(result) => {
				callback(result);
			},false,true,407016
		);
	}
	// 获取省市区列表
	getAllArea(callback) {
		this.postJson({
				url: `${BaseURL}/userGroup/getAllArea`
			},
			(result) => {
				callback(result);
			},false,true,407018
		);
	}
	// 获取省市区版本（暂时未使用）
	getAreaVersion(callback) {
		this.postJson({
				url: `${BaseURL}/userGroup/getAreaVersion`
			},
			(result) => {
				callback(result);
			},false,true,407017
		);
	}

	/** ============================房间============================================================================================= */
	// 新增房间
	addRoom(data, callback) {
		this.postJson({
				url: `${BaseURL}/room/addRoom`,
				data: data
			},
			(result) => {
				callback(result);
			},false,true,407500
		);
	}
	// 删除房间
	delRoom(data, callback) {
		this.postJson({
				url: `${BaseURL}/room/delRoom`,
				data: data
			},
			(result) => {
				callback(result);
			},false,true,407502
		);
	}
	// 编辑房间
	updateRoom(data, callback) {
		this.postJson({
				url: `${BaseURL}/room/updateRoom`,
				data: data
			},
			(result) => {
				callback(result);
			},false,true,407501
		);
	}
	// 分页查询房间列表
	getRoomListByPage(data, callback) {
		this.postJson({
				url: `${BaseURL}/room/getRoomListByPage`,
				data: data
			},
			(result) => {
				callback(result);
			},false,true,407503
		);
	}

	/** ============================用户============================================================================================= */
	// 获取邀请口令（暂时未使用）
	getKey(data, callback, simple = true) {
		this.postJson({
				url: `${BaseURL}/user/getKey`,
				data: data
			},
			(result) => {
				callback(result);
			}, false,simple,407009
		);
	}
	// 解析邀请口令,将用户加到用户组（暂时未使用）
	decodeKey(data, callback) {
		this.postJson({
				url: `${BaseURL}/user/decodeKey`,
				data: data
			},
			(result) => {
				callback(result);
			},false,false,407001
		);
	}
	//单个设备分享
	shareSingleDevice(data, callback) {
		this.postJson({
				url: `${BaseURL}/deviceShare/getShareCode`,
				data: data
			},
			(result) => {
				callback(result);
			}
		);
	}
	//解析单个设备分享的邀请码
	decodeShareCode(data, callback) {
		this.postJson({
				url: `${BaseURL}//deviceShare/decodeShareCode`,
				data: data
			},
			(result) => {
				callback(result);
			},false,false
		);
	}
	//通过分享码接受分享添加该设备
	acceptShareByCode(data, callback) {
		this.postJson({
				url: `${BaseURL}/deviceShare/acceptShareByCode`,
				data: data
			},
			(result) => {
				callback(result);
			}
		);
	}
	//查询别人分享给当前用户的设备列表（当前用户已接收）
	getSharedDeviceList(data, callback) {
		this.postJson({
				url: `${BaseURL}/deviceShare/getSharedDeviceList`,
				data: data
			},
			(result) => {
				callback(result);
			}
		);
	}
	//接受分享者删除被分享的设备
	delRecDevice(data, callback) {
		this.postJson({
				url: `${BaseURL}/deviceShare/delRecDevice`,
				data: data
			},
			(result) => {
				callback(result);
			}
		);
	}
	//分享者删除分享的设备
	delSharedDevice(data, callback) {
		this.postJson({
				url: `${BaseURL}/deviceShare/delSharedDevice`,
				data: data
			},
			(result) => {
				callback(result);
			}
		);
	}
	//根据主pid查询可分享权限列表
	getPrivilegeByPid(data, callback) {
		this.postJson({
				url: `${BaseURL}/deviceShare/selPrivilege`,
				data: data
			},
			(result) => {
				callback(result);
			}
		);
	}
	// 分页查询用户列表或成员
	getUserListByPage(data, callback) {
		this.postJson({
				url: `${BaseURL}/user/getUserListByPage`,
				data: data
			},
			(result) => {
				callback(result);
			},false,true,407014
		);
	}
	// 新增用户到用户组
	addUser(data, callback) {
		this.postJson({
				url: `${BaseURL}/user/addUser`,
				data: data
			},
			(result) => {
				callback(result);
			},false,true,407002
		);
	}
	// 从组中删除用户
	delUser(data, callback) {
		this.postJson({
				url: `${BaseURL}/user/delUser`,
				data: data
			},
			(result) => {
				callback(result);
			},false,true,407005
		);
	}
	// 编辑用户信息（暂时未使用）
	updateUser(data, callback) {
		this.postJson({
				url: `${BaseURL}/user/updateUser`,
				data: data
			},
			(result) => {
				callback(result);
			},false,true,407010
		);
	}
	/** ============================场景============================================================================================= */
	// 查询场景列表
	getSceneList(data, callback) {
		this.postJson({
				url: `${BaseURL}/viot/scenario/scene/getSceneList`,
				data: data
			},
			(result) => {
				callback(result);
			},false,true,407711
		);
	}
	// 查询单个场景
	getScene(data, callback) {
		this.postJson({
				url: `${BaseURL}/viot/scenario/scene/getScene`,
				data: data
			},
			(result) => {
				callback(result);
			},false,true,407712
		);
	}
	// 创建场景
	createScene(data, callback) {
		this.postJson({
				url: `${BaseURL}/viot/scenario/scene/createScene`,
				data: data
			},
			(result) => {
				callback(result);
			},false,true,407701
		);
	}
	// 修改场景
	updateScene(data, callback) {
		this.postJson({
				url: `${BaseURL}/viot/scenario/scene/updateScene`,
				data: data
			},
			(result) => {
				callback(result);
			},false,true,407706
		);
	}
	// 删除场景
	deleteScene(data, callback) {
		this.postJson({
				url: `${BaseURL}/viot/scenario/scene/deleteScene`,
				data: data
			},
			(result) => {
				callback(result);
			},false,true,407704
		);
	}
	// 查询场景条件（暂时未使用）
	getSceneCondition(data, callback) {
		this.postJson({
				url: `${BaseURL}/viot/scenario/condition/getSceneCondition`,
				data: data
			},
			(result) => {
				callback(result);
			}
		);
	}
	// 创建场景条件（暂时未使用）
	createSceneCondition(data, callback) {
		this.postJson({
				url: `${BaseURL}/viot/scenario/scene/createSceneCondition`,
				data: data
			},
			(result) => {
				callback(result);
			}
		);
	}
	// 修改场景条件(暂时未使用)
	updateSceneCondition(data, callback) {
		this.postJson({
				url: `${BaseURL}/viot/scenario/condition/updateSceneCondition`,
				data: data
			},
			(result) => {
				callback(result);
			}
		);
	}
	// 删除场景条件（暂时未使用）
	deleteSceneCondition(data, callback) {
		this.postJson({
				url: `${BaseURL}/viot/scenario/condition/deleteSceneCondition`,
				data: data
			},
			(result) => {
				callback(result);
			}
		);
	}
	// 查询场景任务（暂时未使用）
	getSceneAction(data, callback) {
		this.postJson({
				url: `${BaseURL}/viot/scenario/action/getSceneAction`,
				data: data
			},
			(result) => {
				callback(result);
			}
		);
	}
	// 创建场景任务（暂时未使用）
	createSceneAction(data, callback) {
		this.postJson({
				url: `${BaseURL}/viot/scenario/action/createSceneAction`,
				data: data
			},
			(result) => {
				callback(result);
			}
		);
	}
	// 修改场景任务（暂时未使用）
	updateSceneAction(data, callback) {
		this.postJson({
				url: `${BaseURL}/viot/scenario/action/updateSceneAction`,
				data: data
			},
			(result) => {
				callback(result);
			}
		);
	}
	// 删除场景任务（暂时未使用）
	deleteSceneAction(data, callback) {
		this.postJson({
				url: `${BaseURL}/viot/scenario/action/deleteSceneAction`,
				data: data
			},
			(result) => {
				callback(result);
			}
		);
	}
	// 一键撤防
	stopGroupScenes(data, callback) {
		this.postJson({
				url: `${BaseURL}/viot/scenario/scene/stopGroupScenes`,
				data: data
			},
			(result) => {
				callback(result);
			},false,true,407709
		);
	}
	// 启用场景
	startScene(data, callback) {
		this.postJson({
				url: `${BaseURL}/viot/scenario/scene/startScene`,
				data: data
			},
			(result) => {
				callback(result);
			},false,true,407702
		);
	}
	// 停用场景
	stopScene(data, callback) {
		this.postJson({
				url: `${BaseURL}/viot/scenario/scene/stopScene`,
				data: data
			},
			(result) => {
				callback(result);
			},false,true,407703
		);
	}
	// 一键执行场景
	oneClick(data, callback) {
		this.postJson({
				url: `${BaseURL}/viot/scenario/scene/oneClick`,
				data: data
			},
			(result) => {
				callback(result);
			},false,true,407705
		);
	}
	// 设置默认场景顺序（暂时未使用）
	setDefaultSceneOrder(data, callback) {
		this.postJson({
				url: `${BaseURL}/viot/scenario/scene/setDefaultSceneOrder`,
				data: data
			},
			(result) => {
				callback(result);
			},false,true,407707
		);
	}
	/** ============================图标============================================================================================= */
	// 查询场景图标和颜色列表
	getIconList(callback) {
		this.postJson({
				url: `${BaseURL}/sceneIcon/getIconList`,
				data: {}
			},
			(result) => {
				callback(result);
			},false,true,407710
		);
	}
	/** ============================广告============================================================================================= */
	// 广告位列表查询
	getAdvertSpaceList(callback) {
		this.postJson({
				url: `${BaseURL}/advertSpace/getAdvertSpaceList`
			},
			(result) => {
				callback(result);
			}
		);
	}
	/** ============================ 客服 ============================================================================================= */

	customerUnRead(callback) {
		this.postForm({
				url: `${BaseURL}/api/open/problem/customer/customerUnRead.do`,
				header: {
					Authorization: uni.getStorageSync('accessToken')
				}
			},
			(result) => {
				callback(result);
			}
		);
	}
	/** ============================ 文件上传 ============================================================================================= */
	// 文件上传（暂时未使用）
	fileUpload(data, callback) {
		this.postJson({
				url: `${BaseURL}/file/fileUpload`,
				data: data
			},
			(result) => {
				callback(result);
			}
		);
	}
	/** ============================设备类型============================================================================================= */
	// 通过Pid 查询虚拟设备的序列号
	getVirtualDeviceNoByPID(data, callback) {
		this.postJson({
				url: `${BaseURL}/virtual/device/genDeviceNo`,
				data: data
			},
			(result) => {
				callback(result);
			}
		);
	}
	// 通过Pid 查询设备信息
	getDeviceInfoByPID(data, callback,decode = false, simple = true) {
		this.postJson({
				url: `${BaseURL}/deviceType/getDeviceType`,
				data: data
			},
			(result) => {
				callback(result);
			},decode,simple,401109
		);
	}
	// 查询单个设备类型（暂时未使用）
	getDeviceType(data, callback) {
		this.postJson({
				url: `${BaseURL}/deviceType/getDeviceType`,
				data: data
			},
			(result) => {
				callback(result);
			}
		);
	}
	/** ============================设备类型属性============================================================================================= */
	//分页查询设备类型属性列表
	getDeviceTypePropListByPageForApp(data, callback) {
		this.postJson({
				url: `${BaseURL}/deviceTypeProp/getDeviceTypePropListByPageForApp`,
				data: data
			},
			(result) => {
				callback(result);
			},false,true,409004
		);
	}
	/** ============================设备操控和状态查询============================================================================ */
	// 设备操控接口（暂时未使用）
	setPropStatus(data, callback) {
		this.postJson({
				url: `${BaseURL}/status/setPropStatus`,
				data: data
			},
			(result) => {
				callback(result);
			}
		);
	}
	// 查询设备状态列表（暂时未使用）
	getPropStatusList(data, callback) {
		this.postJson({
				url: `${BaseURL}/status/getPropStatusList`,
				data: data
			},
			(result) => {
				callback(result);
			}
		);
	}
	// 查询设备状态属性
	getDevicePropStatus(data, callback) {
		this.postJson({
				url: `${BaseURL}/status/getDevicePropStatus`,
				data: data
			},
			(result) => {
				callback(result);
			},false,true,409008
		);
	}
	// 宠物喂食器一键喂食
	oneClickFeeding(data, token, callback) {
		this.postJson({
				url: `${BaseURLRDSVIOT}/v2/rtc/device/feeder/${token}`,
				data: data
			},
			(result) => {
				callback(result);
			}
		);
	}
	// 挂断云电话的接口
	voesCallHangup(data, token, callback) {
		this.postJson({
				url: `${BaseURLRDSVIOT}/v2/rtc/device/voesCallHangup/${token}`,
				data: data
			},
			(result) => {
				callback(result);
			}
		);
	}
	// 获取网络模式
	getLoginNetworkMode(data, token, callback) {
		this.postJson({
				url: `${BaseURLRDSVIOT}/v2/rtc/device/getLoginNetworkMode/${token}`,
				data: data
			},
			(result) => {
				callback(result);
			}
		);
	}
	// 获取状态属性
	iotPropGet(data, token, callback) {
		this.postJson({
				url: `${BaseURLRDSVIOT}/v2/rtc/device/iotPropGet/${token}`,
				data: data
			},
			(result) => {
				callback(result);
			}
		);
	}
	// 查询状态变化记录（暂时未使用）
	getPropStatusRecordByPage(data, callback) {
		this.postJson({
				url: `${BaseURL}/status/getPropStatusRecordByPage`,
				data: data
			},
			(result) => {
				callback(result);
			}
		);
	}
	/** ============================设备推荐名============================================================================================= */
	// 根据pid查询设备推荐名列表（暂时未使用）
	getAdviceNameListForApp(data, callback) {
		this.postJson({
				url: `${BaseURL}/adviceName/getAdviceNameListForApp`,
				data: data
			},
			(result) => {
				callback(result);
			},false,true,409005
		);
	}
	/** ============================设备配置============================================================================================= */
	// 根据pid查询设备类型属性列表(设备端接口)（暂时未使用）
	propListForDevice(data, callback) {
		this.postJson({
				url: `${BaseURL}/deviceConfig/propListForDevice`,
				data: data
			},
			(result) => {
				callback(result);
			}
		);
	}
	/** ============================设备============================================================================================= */
	// 设置设备经纬度
	setDeviceLocation(data, callback) {
		this.postJson({
				url: `${BaseURLWeather}/jfweather/device/latlon/save`,
				data: data
			},
			(result) => {
				callback(result);
			}
		);
	}
	// 博克乐鑫定制设备获取临时密码
	getLxTempPwd(data, callback) {
		this.postJson({
				url: `${BaseURL}/tempPwd/selTempPwd`,
				data: data
			},
			(result) => {
				callback(result);
			}
		);
	}
	// 博克乐鑫定制设备设置临时密码
	setLxTempPwd(data, callback) {
		this.postJson({
				url: `${BaseURL}/tempPwd/setTempPwd`,
				data: data
			},
			(result) => {
				callback(result);
			}
		);
	}
	//新增临时密码
	addTempPwd(data, callback) {
		this.postJson({
				url: `${BaseURL}/tempPwd/add`,
				data: data
			},
			(result) => {
				callback(result);
			}
		);
	}
	//修改临时密码
	updateTempPwd(data, callback) {
		this.postJson({
				url: `${BaseURL}/tempPwd/update`,
				data: data
			},
			(result) => {
				callback(result);
			}
		);
	}
	//删除临时密码
	delTempPwd(data, callback) {
		this.postJson({
				url: `${BaseURL}/tempPwd/del`,
				data: data
			},
			(result) => {
				callback(result);
			}
		);
	}
	// 获取消息级别
	getUserAlarm(data, callback) {
		this.postJson({
				url: `${BaseURL}//userAlarm/getUserAlarm`,
				data: data
			},
			(result) => {
				callback(result);
			}
		);
	}
	//查询添加设备全部引导页
	getDeviceGuidePageList(data, callback) {
		this.postJson({
				url: `${BaseURL}/guidePage/getList`,
				data: data
			},
			(result) => {
				callback(result);
			},false,true,409011
		);
	}
	//通过pageId 查询特定引导页
	getDeviceGuideByPageId(data, callback) {
		this.postJson({
				url: `${BaseURL}/guidePage/selPageContent`,
				data: data
			},
			(result) => {
				callback(result);
			}
		);
	}
	// 分页查询当前用户设备列表
	getUserDeviceListByPage(data, callback) {
		this.postJson({
				url: `${BaseURL}/device/getUserDeviceListByPage`,
				data: data
			},
			(result) => {
				callback(result);
			},false,true,409013
		);
	}
	// 设备分类列表
	getDeviceSortListByPage(data, callback) {
		this.postJson({
				url: `${BaseURL}/object/getObjectListForApp`,
				data: data
			},
			(result) => {
				callback(result);
			},false,true,409001
		);
	}
	// 设备分类对应的设备列表
	getDeviceSortForDeviceType(data, callback) {
		this.postJson({
				url: `${BaseURL}/deviceType/getDeviceTypeListByPageForApp`,
				data: data
			},
			(result) => {
				callback(result);
			},false,true,409002
		);
	}
	// 获取设备是否可以添加
	deviceExistence(data, callback) {
		this.postJson({
				url: `${BaseURL}/device/deviceExistence`,
				data: data
			},
			(result) => {
				callback(result)
			},false,true
		)
	}
	//查询所有设备列表
	getAllDeviceList(data, callback) {
		this.postJson({
				url: `${BaseURL}/device/getDeviceListForAisvr`,
				data: data
			},
			(result) => {
				callback(result);
			}
		);
	}
	// 分页查询设备列表，根据房间id或者用户组id或用户id,查询具体的某个设备
	getDeviceListByPage(data, callback) {
		this.postJson({
				url: `${BaseURL}/device/getDeviceListByPage`,
				data: data
			},
			(result) => {
				callback(result);
			},false,true,409003
		);
	}
	// 获取设备token和登录名密码（本地接口,暂时未使用）
	getDeviceTokenLocal(data, callback) {
		this.postJson({
				url: `${BaseURL}/device/getDeviceToken`,
				data: data
			},
			(result) => {
				callback(result);
			},false,true,409006
		);
	}
	// 判断设备是否可以增加 (新增接口有判断，暂时未使用)
	deviceExistence(data, callback) {
		this.postJson({
				url: `${BaseURL}/device/deviceExistence`,
				data: data
			},
			(result) => {
				callback(result);
			}
		);
	}
	// 新增设备到用户组
	addDevice(data, callback, decode = false, simple = true) {
		this.postJson({
				url: `${BaseURL}/device/addDevice`,
				data: data
			},
			(result) => {
				callback(result);
			},
			decode,
			simple
		);
	}
	// 添加设备到房间 (废弃)
	addDeviceToRoom(data, callback) {
		this.postJson({
				url: `${BaseURL}/device/addDeviceToRoom`,
				data: data
			},
			(result) => {
				callback(result);
			}
		);
	}
	// 移动设备到某房间
	moveDeviceToRoom(data, callback,decode = false, simple = true) {
		this.postJson({
				url: `${BaseURL}/device/moveDeviceToRoom`,
				data: data
			},
			(result) => {
				callback(result);
			},decode,simple,409201
		);
	}
	// 根据用户组id和用户id，分页查询无权限的设备列表（暂时未使用）
	deviceListWithOutPrivilegeByPage(data, callback) {
		this.postJson({
				url: `${BaseURL}/device/deviceListWithOutPrivilegeByPage`,
				data: data
			},
			(result) => {
				callback(result);
			}
		);
	}
	// 根据用户组id和场景信息，分页查询设备列表(暂时未使用)
	getDeviceListByScene(data, callback) {
		this.postJson({
				url: `${BaseURL}/device/getDeviceListByScene`,
				data: data
			},
			(result) => {
				callback(result);
			}
		);
	}
	// 根据用户权限，分页查询未分配房间的设备列表，也可以具体查询某一个设备 (暂时未使用)
	getDeviceListWithoutRoomByPage(data, callback) {
		this.postJson({
				url: `${BaseURL}/device/getDeviceListWithoutRoomByPage`,
				data: data
			},
			(result) => {
				callback(result);
			}
		);
	}
	// 设备位置信息 （暂时未使用）
	getDeviceLocation(callback) {
		this.postJson({
				url: `${BaseURL}/device/location/getDeviceLocation`
			},
			(result) => {
				callback(result);
			}
		);
	}
	// 判断设备是否可以添加 (暂时未使用)
	deviceExistence(data, callback) {
		this.postJson({
				url: `${BaseURL}/device/deviceExistence`,
				data: data
			},
			(result) => {
				callback(result);
			}
		);
	}
	// 获取设备当前属性状态列表 (暂时未使用)
	getDeviceStatusLocal(data, callback) {
		this.postJson({
				url: `${BaseURL}/device/getDeviceStatus`,
				data: data
			},
			(result) => {
				callback(result);
			}
		);
	}
	// 添加设备使用权限给普通组员
	addDeviceToUser(data, callback) {
		this.postJson({
				url: `${BaseURL}/device/addDeviceToUser`,
				data: data
			},
			(result) => {
				callback(result);
			}
		);
	}
	// 取消普通组员设备使用权限 (暂时未使用)
	delDeviceFromUser(data, callback) {
		this.postJson({
				url: `${BaseURL}/device/delDeviceFromUser`,
				data: data
			},
			(result) => {
				callback(result);
			}
		);
	}
	// 从房间移除设备（暂时未使用）
	delDeviceFromRoom(data, callback) {
		this.postJson({
				url: `${BaseURL}/device/delDeviceFromRoom`,
				data: data
			},
			(result) => {
				callback(result);
			}
		);
	}
	// 删除设备
	delDevice(data, callback, decode = false, simple = true) {
		this.postJson({
				url: `${BaseURL}/device/delDevice`,
				data: data
			},
			(result) => {
				callback(result);
			},false,true,409202
		);
	}
	// 编辑设备
	updateDevice(data, callback) {
		this.postJson({
				url: `${BaseURL}/device/updateDevice`,
				data: data
			},
			(result) => {
				callback(result);
			},false,true,409203
		);
	}
	/** ============================设备音频========================================================================================== */
	//  根据pid查询设备音频列表（暂时未使用）
	getDeviceAudioListForApp(data, callback) {
		this.postJson({
				url: `${BaseURL}/deviceAudio/getDeviceAudioListForApp`,
				data: data
			},
			(result) => {
				callback(result);
			}
		);
	}
	/** ============================协议转换========================================================================================== */
	// 设备数据转json（暂时未使用）
	dataToJson(data, callback) {
		this.postJson({
				url: `${BaseURL}/protocol/dataToJson`,
				data: data
			},
			(result) => {
				callback(result);
			}
		);
	}
	// json转设备数据（暂时未使用）
	jsonToData(data, callback) {
		this.postJson({
				url: `${BaseURL}/protocol/jsonToData`,
				data: data
			},
			(result) => {
				callback(result);
			}
		);
	}
	// 获取设备状态命令（暂时未使用）
	getDeviceStatusProtocol(data, callback) {
		this.postJson({
				url: `${BaseURL}/protocol/getDeviceStatus`,
				data: data
			},
			(result) => {
				callback(result);
			}
		);
	}
	/** ============================ 设备定时任务 ============================================================================================= */
	// 查询定时任务（暂时未使用）
	selectTimerByPage(data, callback) {
		this.postJson({
				url: `${BaseURL}/deviceTimer/selectTimerByPage`,
				data: data
			},
			(result) => {
				callback(result);
			}
		);
	}
	// 创建定时任务（暂时未使用）
	addTimer(data, callback) {
		this.postJson({
				url: `${BaseURL}/deviceTimer/addTimer`,
				data: data
			},
			(result) => {
				callback(result);
			}
		);
	}
	// 更新定时任务（暂时未使用）
	updateTimer(data, callback) {
		this.postJson({
				url: `${BaseURL}/deviceTimer/updateTimer`,
				data: data
			},
			(result) => {
				callback(result);
			}
		);
	}
	// 删除定时任务（暂时未使用）
	deleteTimer(data, callback) {
		this.postJson({
				url: `${BaseURL}/deviceTimer/deleteTimer`,
				data: data
			},
			(result) => {
				callback(result);
			}
		);
	}
	// 将某设备所有定时计划转为二进制的base64数据（暂时未使用）
	timerToData(data, callback) {
		this.postJson({
				url: `${BaseURL}/deviceTimer/timerToData`,
				data: data
			},
			(result) => {
				callback(result);
			}
		);
	}
	/** ============================ 宠物 ============================================================================================= */
	// 创建宠物档案（暂时未使用）
	createPetArchives(data, callback) {
		this.postJson({
				url: `${BaseURL}/user/pet/archives/createPetArchives`,
				data: data
			},
			(result) => {
				callback(result);
			}
		);
	}
	// 更新宠物档案（暂时未使用）
	updatePetArchives(data, callback) {
		this.postJson({
				url: `${BaseURL}/user/pet/archives/updatePetArchives`,
				data: data
			},
			(result) => {
				callback(result);
			}
		);
	}
	// 删除宠物档案（暂时未使用）
	deletePetArchives(data, callback) {
		this.postJson({
				url: `${BaseURL}/user/pet/archives/deletePetArchives`,
				data: data
			},
			(result) => {
				callback(result);
			}
		);
	}
	// 查询宠物档案（暂时未使用）
	getPetArchivesList(data, callback) {
		this.postJson({
				url: `${BaseURL}/user/pet/archives/getPetArchivesList`,
				data: data
			},
			(result) => {
				callback(result);
			}
		);
	}
	// 查询宠物种类（暂时未使用）
	getPetTypeList(data, callback) {
		this.postJson({
				url: `${BaseURL}/user/pet/type/getPetTypeList`,
				data: data
			},
			(result) => {
				callback(result);
			}
		);
	}
	// 查询宠物品种（暂时未使用）
	getPetBreedList(data, callback) {
		this.postJson({
				url: `${BaseURL}/user/pet/breed/getPetBreedList`,
				data: data
			},
			(result) => {
				callback(result);
			}
		);
	}
	/** ============================ 设备鉴权 ========================================================================================== */
	// 获取设备token
	getDeviceToken(data, callback) {
		this.postJson({
				url: `${BaseURLRS}/v2/device/token/${this.tms}/${this.sig}.rs`,
				data: data
			},
			(result) => {
				callback(result);
			}
		);
	}
	/** ============================设备云存储========================================================================================== */
	// 获取云存储状态
	// ICCID
	reqCaps(data, callback) {
		this.postJson({
				url: `${BaseURLCAPSXM}/api/reqCaps/v2/${this.tms}/${this.sig}.caps`,
				data: data
			},
			(result) => {
				callback(result);
			}
		);
	}
	// 制造方式
	queryDevice(data, token, callback) {
		this.postJson({
				url: `${BaseURLCAPSXM}/api/queryDevice/v2/${this.tms}/${this.sig}.caps?sn=` + data.sn
			},
			(result) => {
				callback(result);
			}
		);
	}

	/** ============================设备功能接口（RESTfull API） =============================================================================== */
	// 获取查看预览视频的人数
	getStreamConnectionsNum(data, token, callback) {
		this.postJson({
				url: `${BaseURLRDSVIOT}/v2/rtc/device/getStreamConnectionsNum/${token}`,
				data: data, //{liveAddress:BaseURLRDS.split('//')[1]}
			},
			(result) => {
				callback(result);
			}
		);
	}
	// 获取设备状态------新的接口
	getNewDeviceStatus(data, callback) {
		this.postJson({
				url: `${BaseURLRDSVIOT}/v2/rtc/device/status`,
				data: data
			},
			(result) => {
				callback(result);
			}
		);
	}
	// 获取设备状态 getDeviceStatus   getNewDeviceStatus
	getDeviceStatus(data, callback) {
		this.postJson({
				url: `${BaseURLRDSVIOT}/v2/rtc/device/statusGlobal`,
				data: data
			},
			(result) => {
				callback(result);
			}
		);
	}
	// 获取门锁配置
	doorLockTransparent(data, token, callback,simple=true) {
		this.postJson({
				url: `${BaseURLRDSVIOT}/v2/rtc/device/doorLockTransparent/${token}`,
				data: data
			},
			(result) => {
				callback(result);
			},false,simple
		);
	}
	// 获取设备上报接口
	getTailoredConfig(data, token, callback) {
		this.postJson({
				url: `${BaseURLRDSVIOT}/v2/rtc/device/getTailoredConfig/${token}`,
				data: data
			},
			(result) => {
				callback(result);
			}
		);
	}
	// 设置设备上报信息
	setTailoredConfig(data, token, callback) {
		this.postJson({
				url: `${BaseURLRDSVIOT}/v2/rtc/device/setTailoredConfig/${token}`,
				data: data
			},
			(result) => {
				callback(result);
			}
		);
	}
	// rds获取设备状态
	getRdsDeviceStatus(data, callback) {
		this.postJson({
				url: `${BaseURLRDSVIOT}/v2/rtc/device/statusGlobal`,
				data: data
			},
			(result) => {
				callback(result);
			}
		);
	}
	// 低功耗设备唤醒
	wakeup(data, token, callback, decode, simple) {
		this.postJson({
				url: `${BaseURLRDSVIOT}/v2/rtc/device/wakeup/${token}`,
				data: data
			},
			(result) => {
				callback(result);
			}, decode,
			simple
		);
	}
	// 获取设备直播地址
	livestream(data, token, callback, decode, simple) {
		this.postJson({
				url: `${BaseURLRDSVIOT}/v2/rtc/device/livestream/${token}`,
				data: data
			},
			(result) => {
				callback(result);
			},
			decode,
			simple
		);
	}
	//获取对讲地址
	talkbackUrl(data, token, callback, decode, simple) {
		this.postJson({
				url: `${BaseURLRDSVIOT}/v2/rtc/device/talkbackUrl/${token}`,
				data: data
			},
			(result) => {
				callback(result);
			},
			decode,
			simple
		);
	}
	//获取视频双向对讲地址
	getTwoWayVideoUrl(data, token, callback, decode, simple) {
		this.postJson({
				url: `${BaseURLRDSVIOT}/v2/rtc/device/getVideoCallUrl/${token}`,
				data: data
			},
			(result) => {
				callback(result);
			},
			decode,
			simple
		);
	}
	// 获取设备基本信息
	getinfo(data, token, callback, decode = false, simple = true) {
		this.postJson({
				url: `${BaseURLRDSVIOT}/v2/rtc/device/getinfo/${token}`,
				data: data
			},
			(result) => {
				callback(result);
			}, decode, simple
		);
	}
	// 设备登录
	deviceLogin(data, token, callback, callbackError) {
		this.postJsonMultifield({
				url: `${BaseURLRDSVIOT}/v2/rtc/device/login/${token}`,
				data: data
			},
			(result) => {
				callback(result);
			},
			false,
			false,
			'text',
			(err) => {
				callbackError()
			}
		);
	}
	// 设备登出
	deviceLogOut(data, token, callback) {
		this.postJson({
				url: `${BaseURLRDSVIOT}/v2/rtc/device/logout/${token}`,
				data: data
			},
			(result) => {
				callback(result);
			},
			false,
			false
		);
	}
	//rds设备登录
	deviceRdsLogin(data, token, callback) {
		this.postJson({
				url: `${BaseURLRDSVIOT}/v2/rtc/device/login/${token}`,
				data: data
			},
			(result) => {
				callback(result);
			},
			false,
			false
		);
	}
	// 保活
	keepAlive(token, callback) {
		this.postJson({
				url: `${BaseURLRDSVIOT}/v2/rtc/device/keepalive/${token}`,
				data: {
					Name: 'KeepAlive'
				}
			},
			(result) => {
				callback(result);
			},
			false,
			false
		);
	}
	// 设备暂停、恢复解码、远程呼叫
	avDecode(data, token, callback,decode = false, simple = true) {
		this.postJson({
				url: `${BaseURLRDSVIOT}/v2/rtc/device/avDecoder/${token}`,
				data: data
			},
			(result) => {
				callback(result);
			},decode, simple
		);
	}
	// 获取设备能力集
	getability(data, token, callback,decode = false, simple = true) {
		this.postJson({
				url: `${BaseURLRDSVIOT}/v2/rtc/device/getability/${token}`,
				data: data
			},
			(result) => {
				callback(result);
			},decode, simple
		);
	}
	// 获取门锁设备能力集
	getdoorLocktability(data, token, callback, decode = false, simple = true) {
		this.postJson({
				url: `${BaseURLRDSVIOT}/v2/rtc/device/getability/${token}`,
				data: data
			},
			(result) => {
				callback(result);
			},decode, simple
		);
	}
	// 获取设备配置
	getconfig(data, token, callback, decode = false, simple = true) {
		this.postJson({
				url: `${BaseURLRDSVIOT}/v2/rtc/device/getconfig/${token}`,
				data: data
			},
			(result) => {
				callback(result);
			}, decode, simple
		);
	}
	// 设置设备配置
	setconfig(data, token, callback, decode, simple) {
		this.postJson({
				url: `${BaseURLRDSVIOT}/v2/rtc/device/setconfig/${token}`,
				data: data
			},
			(result) => {
				callback(result);
			}, decode, simple
		);
	}
	//远程开锁
	remoteUnlock(data, token, callback) {
		this.postJson({
				url: `${BaseURLRDSVIOT}/v2/rtc/device/doorLockRemoteUnlock/${token}`,
				data: data
			},
			(result) => {
				callback(result);
			}
		);
	}
	// 设置临时密码
	setTemporaryPassword(data, token, callback) {
		this.postJson({
				url: `${BaseURLRDSVIOT}/v2/rtc/device/doorLockSetTempPassword/${token}`,
				data: data
			},
			(result) => {
				callback(result);
			}
		);
	}
	//获取升级进度
	getUpgradeProgress(data, token, callback, decode, simple) {
		this.postJson({
				url: `${BaseURLRDSVIOT}/v2/rtc/device/getUpgradeProgress/${token}`,
				data: data
			},
			(result) => {
				callback(result);
			}, false, false
		);
	}
	// 设备操作-v2版
	opdev(data, token, callback, decode = false, simple = true) {
		this.postJson({
				url: `${BaseURLRDSVIOT}/v2/rtc/device/opdev/${token}`,
				data: data
			},
			(result) => {
				callback(result);
			},
			decode,
			simple
		);
	}
	// 设备操作-v1版
	opdevXm(data, token, callback) {
		this.postJson({
				url: `${BaseURLRDSXM}/v1/rtc/device/opdev/${token}`,
				data: data
			},
			(result) => {
				callback(result);
			}
		);
	}
	//设备抓图
	capture(data, token, callback) {
		this.postJson({
				url: `${BaseURLRDSVIOT}/v2/rtc/device/capture/${token}`,
				data: data
			},
			(result) => {
				callback(result);
			}
		);
	}
	// 设备用户相关
	usermanage(data, token, callback) {
		this.postJson({
				url: `${BaseURLRDSVIOT}/v2/rtc/device/usermanage/${token}`,
				data: data
			},
			(result) => {
				callback(result);
			}
		);
	}
	// 门锁报警消息列表
	getLockAlarmMSgList(data, token, callback) {
		this.postJson({
				url: `${BaseURLRDSVIOT}/v2/rtc/device/getDeviceAlarmList/${token}`,
				data: data
			},
			(result) => {
				callback(result);
			}
		);
	}
	// 删除云事件消息
	deleteLockAlarmMSg(data, token, callback) {
		this.postJson({
				url: `${BaseURLRDSVIOT}/v2/rtc/device/deleteDeviceAlarmInfo/${token}`,
				data: data
			},
			(result) => {
				callback(result);
			}
		);
	}
	//新增或修改消息昵称
	editLockAlarmMSgName(data, callback) {
		this.postJson({
				url: `${BaseURL}/doorLockUserNickname/insertOrUpdate`,
				data: data
			},
			(result) => {
				callback(result);
			}
		);
	}
	//查询消息昵称
	getLockAlarmMSgName(data, callback) {
		this.postJson({
				url: `${BaseURL}/doorLockUserNickname/listNicknameForApp`,
				data: data
			},
			(result) => {
				callback(result);
			}
		);
	}
	// 设备报警消息订阅
	subscribeMessage(data, token, callback) {
		this.postJson({
				url: `${BaseURLRDSVIOT}/v2/rtc/device/subscribeMessage/${token}`,
				data: data
			},
			(result) => {
				callback(result);
			}
		);
	}
	// 设备报警消息取消订阅
	unsubscribeMessage(token, callback) {
		this.postJson({
				url: `${BaseURLRDSVIOT}/v2/rtc/device/unsubscribeMessage/${token}`
			},
			(result) => {
				callback(result);
			}
		);
	}
	// 语音电话功能
	voesSetInfo(data, token, callback) {
		this.postJson({
				url: `${BaseURLRDSVIOT}/v2/rtc/device/voesSetInfo/${token}`,
				data: data
			},
			(result) => {
				callback(result);
			}
		);
	}
	//获取消息列表报警视频（新的接口）
	downloadVideo(data, token, callback) {
		this.postJsonMultifield({
				url: `${BaseURLRDSVIOT}/v2/rtc/device/downloadVideo/${token}`,
				data: data
			},
			(result) => {
				callback(result);
			}, false, false, 'arraybuffer'
		);
	}
	// 通过报警ID获取报警图片地址
	getPicUrl(data, token, callback, decode, simple) {
		this.postJson({
				url: `${BaseURLRDSVIOT}/v2/rtc/device/getPicUrl/${token}`,
				data: data
			},
			(result) => {
				callback(result);
			}, decode, simple
		);
	}
	// 获取报警视频地址
	getVideoUrl(data, token, callback) {
		this.postJson({
				url: `${BaseURLRDSVIOT}/v2/rtc/device/getVideoUrl/${token}`,
				data: data
			},
			(result) => {
				callback(result);
			}
		);
	}
	// 停止设备码流
	closeLivestream(data, token, callback, decode, simple) {
		this.postJson({
				url: `${BaseURLRDSVIOT}/v2/rtc/device/closeLivestream/${token}`,
				data: data
			},
			(result) => {
				callback(result);
			},
			decode, simple

		);
	}
	//获取云存视频列表
	getCloudVideoList(data, token, callback) {
		this.postJson({
				url: `${BaseURLRDSVIOT}/v2/rtc/device/get
				VideoList/${token}`,
				data: data
			},
			(result) => {
				callback(result);
			}
		);
	}
	// 获取云回放视频的缩略图
	getCloudVideoIcon(data, token, callback) {
		this.postJson({
				url: `${BaseURLRDSVIOT}/v2/rtc/device/getVideoPicUrl/${token}`,
				data: data
			},
			(result) => {
				callback(result);
			}
		);
	}
	// 获取设备回放地址
	playbackUrl(data, token, callback) {
		this.postJson({
				url: `${BaseURLRDSVIOT}/v2/rtc/device/playbackUrl/${token}`,
				data: data
			},
			(result) => {
				callback(result);
			}
		);
	}
	// 制造方式
	queryDevice(data, token, callback) {
		this.postJson({
				url: `${BaseURLCAPSXM}/api/queryDevice/v2/${this.tms}/${this.sig}.caps?sn=` + data.sn
			},
			(result) => {
				callback(result);
			}
		);
	}
	// ICCID
	reqCaps(data, callback) {
		this.postJson({
				url: `${BaseURLCAPSXM}/api/reqCaps/v2/${this.tms}/${this.sig}.caps`,
				data: data
			},
			(result) => {
				callback(result);
			}
		);
	}
	// 发布状态
	getfindRelease(data, callback) {
		this.postJson({
				url: `${BaseURLSW}/soft/api/infoVersionView/findRelease`,
				data: data
			},
			(result) => {
				callback(result);
			}
		);
	}

	//获取视频双向对讲地址 V3
	getTwoWayVideoUrlV3(params,token, callback,simple) {
		const options = {
			url: `${BaseURLGWP}/v3/rtc/device/getVideoCallUrl/${token}`,
			method: "POST",
			params,
		}
		// console.log(isAES(params), '加密的参数')
		requestV3(options,
				(result)=>{
					callback(result)
				},simple)
	}
	bindDeviceV3(params, callback,simple) {
		const options = {
			url: `${BaseURLGWP}/v3/rtc/device/bind`,
			method: "POST",
			params,
		}
		// console.log(isAES(params), '加密的参数')
		requestV3(options,
				(result)=>{
					callback(result)
				},simple)
	}
	unbindDeviceV3(params,token, callback,simple) {
		const options = {
			url: `${BaseURLGWP}/v3/rtc/device/unbind/${token}`,
			method: "POST",
			params,
		}
		// console.log(isAES(params), '加密的参数')
		requestV3(options,
				(result)=>{
					callback(result)
				},simple)
	}
	getDeviceTokenV3(params, callback) {
		console.log('params',params)
		const options = {
			url: `${BaseURLRDS}/gwp/v3/rtc/device/token`,
			method: "POST",
			params,
		}
		console.log('options',options)

		// console.log(isAES(params), '加密的参数')
		requestV3(options,
				(result)=>{
					callback(result)
				})
	}
	getDeviceLoginToken(params,token,callback,simple){
		const options = {
			url: `${BaseURLRDS}/gwp/v3/rtc/device/queryLoginToken/${token}`,
			method: "POST",
			params,
		}
		// console.log(isAES(params), '加密的参数')
		requestV3(options,
				(result)=>{
					callback(result)
				},simple)
	}
	// 设备登录V3
	deviceLoginV3(params,token,callback,simple) {
		const options = {
			url: `${BaseURLRDSVIOT}/v3/rtc/device/login/${token}`,
			method: "POST",
			params,
		}
		// console.log(isAES(params), '加密的参数')
		requestV3(options,
			(result)=>{
				callback(result)
			},simple)
	}
	// 获取设备能力集V3
	getabilityV3(params,token,callback,simple) {
		const options = {
			url: `${BaseURLRDSVIOT}/v3/rtc/device/getability/${token}`,
			method: "POST",
			params,
		}
		// console.log(isAES(params), '加密的参数')
		requestV3(options,
			(result)=>{
				callback(result)
			},simple)
	}
	// 根据应用获取设备列表
	getDeviceListV3ByApp(params, callback) {
		const options = {
			url: `${BaseURLGWP}/v3/rtc/device/list`,
			method: "POST",
			params,
		}
		// console.log(isAES(params), '加密的参数')
		requestV3(options,
				(result)=>{
					callback(result)
				})
	}
}